using MicroMsg.UI.Page;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Media;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class AlbumItemView : UserControl
	{
		public delegate void AlbumItemClick(object sender, object object_0);
		private PictureAlbum mAlbum;
		private static Dictionary<string, string> name_showName_map;
		internal Button LayoutItem;
		internal Image image;
		internal Grid txtCountLayout;
		internal TextBlock txtCount;
		internal Grid txtTitleLayout;
		internal DynamicTextBlock txtTitle;
		private bool _contentLoaded;
		public event AlbumItemView.AlbumItemClick ItemClick;
		public AlbumItemView()
		{
			if (AlbumItemView.name_showName_map == null)
			{
				AlbumItemView.name_showName_map = new Dictionary<string, string>();
				AlbumItemView.name_showName_map.Add("Saved Pictures", "MultiPhotoChooser_SavedPics");
				AlbumItemView.name_showName_map.Add("Camera Roll", "MultiPhotoChooser_CameraRoll");
				AlbumItemView.name_showName_map.Add("Pictures", "MultiPhotoChooser_OtherPics");
			}
			this.InitializeComponent();
			base.SetValue(TiltEffect.IsTiltEnabledProperty, true);
			this.LayoutItem.set_DataContext(this);
		}
		public void SetAlbum(PictureAlbum album)
		{
			this.mAlbum = album;
			if (album != null)
			{
				base.set_Tag(album);
				base.set_Visibility(0);
				BitmapImage bitmapImage = new BitmapImage();
				bitmapImage.SetSource(album.get_Pictures().get_Item(0).GetThumbnail());
				this.image.set_Source(bitmapImage);
				this.txtTitle.Text = this.getRealAlbumName(album);
				this.ReSetSelectedCount();
				return;
			}
			base.set_Visibility(1);
		}
		private string getRealAlbumName(PictureAlbum album)
		{
			string result = album.get_Name();
			if (AlbumItemView.name_showName_map.ContainsKey(album.get_Name()))
			{
				string string_ = AlbumItemView.name_showName_map.get_Item(album.get_Name());
				string stringByKey = R.GetStringByKey(string_);
				if (!string.IsNullOrEmpty(stringByKey))
				{
					result = stringByKey;
				}
			}
			return result;
		}
		private int getSelectedCount()
		{
			if (this.mAlbum == null)
			{
				return 0;
			}
			int num = 0;
			using (IEnumerator<Picture> enumerator = this.mAlbum.get_Pictures().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Picture current = enumerator.get_Current();
					if (MultiPhotoChooser.sSelectedPictures.Contains(current))
					{
						num++;
					}
				}
			}
			return num;
		}
		public void ReSetSelectedCount()
		{
			int selectedCount = this.getSelectedCount();
			if (selectedCount > 0)
			{
				this.txtCount.set_Text(string.Concat(selectedCount));
				this.txtCountLayout.set_Visibility(0);
				return;
			}
			this.txtCount.set_Text("");
			this.txtCountLayout.set_Visibility(1);
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, null);
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Util/MultiPhotoChooser/AlbumItemView.xaml", 2));
			this.LayoutItem = (Button)base.FindName("LayoutItem");
			this.image = (Image)base.FindName("image");
			this.txtCountLayout = (Grid)base.FindName("txtCountLayout");
			this.txtCount = (TextBlock)base.FindName("txtCount");
			this.txtTitleLayout = (Grid)base.FindName("txtTitleLayout");
			this.txtTitle = (DynamicTextBlock)base.FindName("txtTitle");
		}
	}
}
